unit con_NaoConformidade;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  Formulario_Padrao_Consulta, StdCtrls, Buttons, ExtCtrls, Grids, DBGrids,dbtables,db;

type
  TFrmCon_NaoConformidade = class(TFrmConsulta)
    Label1: TLabel;
    edtDescricao: TEdit;
    DBGrid: TDBGrid;
    procedure FormActivate(Sender: TObject);
    procedure BtnFecharClick(Sender: TObject);
    procedure edtDescricaoKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure FormCreate(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
  private
    { Private declarations }
  public
    { Public declarations }
    cod_ncf : string;
    procedure FazConsulta;
  end;

var
  FrmCon_NaoConformidade: TFrmCon_NaoConformidade;

implementation

uses clsNao_Conformidade,biblio,dm;

var
  Nao_conformidade : TNao_Conformidade;
  tq  : TQuery;
  tds : TDataSource;

{$R *.DFM}

procedure TFrmCon_NaoConformidade.FazConsulta;
begin
  if edtDescricao.Text = '' then
    edtDescricao.Text := ' ';
  Nao_conformidade.Consultar(tq,edtDescricao.Text);
  tq.open;
  DBGrid.DataSource := tds;
  DBGrid.Refresh;
end;

procedure TFrmCon_NaoConformidade.FormActivate(Sender: TObject);
begin
  inherited;
  tq := TQuery.create(DmInt);
  tq.DatabaseName := DmInt.Db.DatabaseName;
  tds        := TDataSource.create(DmInt);
  tq.Active  := false;
  tds.DataSet:= tq;
  FazConsulta;
  edtDescricao.SetFocus;
end;

procedure TFrmCon_NaoConformidade.BtnFecharClick(Sender: TObject);
begin
  inherited;
  cod_ncf := tq.fieldbyname('cod_ncf').AsString;
  tq.close;
  tq.free;
  tds.free;
end;

procedure TFrmCon_NaoConformidade.edtDescricaoKeyDown(Sender: TObject;
  var Key: Word; Shift: TShiftState);
begin
  inherited;
  if key = 12 then
  begin
    FazConsulta;
    edtDescricao.SetFocus;
  end;
end;

procedure TFrmCon_NaoConformidade.FormCreate(Sender: TObject);
begin
  inherited;
  Nao_conformidade := TNao_Conformidade.create;
end;

procedure TFrmCon_NaoConformidade.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
  inherited;
  Nao_conformidade.free;
end;

end.
